<?php
class DB_Pdo extends PDO{
                    protected $user = 'username';
                    protected $password = 'password';
                    protected $hostname= '127.0.0.1';
                    protected $database = 'database';
	function __construct(){
		

		        parent::__construct("mysql:dbname=$this->database;host=$this->hostname",$this->user,$this->password);
		        //$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DB_PdoStatement', array($this)));
				//$this->setAttribute( PDO::ATTR_STATEMENT_CLASS, array( $this->DB_PdoStatement, array() ) );//be.php.net/pdo post by ob.php 30-12-2007
				$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 
				$this->setAttribute(PDO::ATTR_PERSISTENT, true); 
				parent::exec('SET CHARACTER SET utf8');// put database in utf8 mode
				parent::exec("SET Names 'utf8'");
    }
	function quoteArray($myarray){
		$return = array();
		if(!is_array($myarray)){
			throw new Exception ('quoteArray expects array as parameter');
		}
		else{
			foreach ($myarray as $item){
				$quoted = parent::quote($item);
				array_push($return,$quoted);
			}
		}
		return $return;
	}
	
	function getColumnNames($table){
			$temp = new PDO("mysql:dbname=$this->database;host=$this->hostname",$this->user,$this->password);
			$querystring = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME ='$table'"; 
			$results= array();
			foreach($temp->query($querystring) as $row){array_push($results, $row['COLUMN_NAME']);}
			return $results;
	}
	
	function help(){
		$class_methods = get_class_methods(new DB_PDO());
		echo "<h1>Class Methods</h1>";
		foreach ($class_methods as $method_name) {
    		echo "$method_name<br />";
		}
	}

}

class DB_PdoStatement extends PDOStatement {
   	public $dbh;
   	protected function __construct($dbh) {
       	$this->dbh = $dbh;
   	}

}

?>
<?php
/*
try{
$S= new DB_Pdo('vandersanden');
$result=$S->prepare("select * from Case_studies");
$result->execute();
while ($obj = $result->fetch(PDO::FETCH_OBJ)){
	echo $obj->id;
	echo $obj->Title;
}
}
catch (DB_PdoStatement $e) {
	
}
*/
?>
<?php
/*
		$db_host='213.193.228.252';
		$db_user='vandersandenl';
		$db_pass='bnH3wxPA';
		$db_name='vandersandenl';
		
		$settings = parse_ini_file("/var/www/vhosts/designexpress.be/private/db_config/vandersanden.ini");
		$user = $settings['username'];
		$password = $settings['password'];
		$hostname= $settings['hostname'];
		$database= $settings['database'];
		$driver= $setting['driver'];
		$errorsettings = parse_ini_file("/var/www/vhosts/designexpress.be/private/db_config/errorManager.ini");
		$erroruser = $errorsettings['username'];
		$errorpassword = $errorsettings['password'];
		$errorhostname= $errorsettings['hostname'];
		$errordatabase= $errorsettings['database'];
		$errordriver= $errorsetting['driver'];

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$database", $user, $password);
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$result = $dbh->query('select * from Case_stuies');
	//$result = $dbh->prepare("select * from Case_studies");
	$result->execute();
	while($obj=$result->fetch(PDO::FETCH_OBJ)){
	echo $obj->id;
	echo $obj->Title;
	}
				 
    $dbh = null;
} 
catch (PDOException $e) {
	$errorFile= $e->getFile();
	$errorMsg = $e->getMessage();
	$referer = $_SERVER['HTTP_REFERER'];
	$pageWithError = $_SERVER["PHP_SELF"];
	$ip = $_SERVER['REMOTE_ADDR'];
	$time =Date('Y-m-d');
	
	
	$dbh = new PDO("mysql:host=$errorhostname;dbname=$errordatabase", $erroruser, $errorpassword);
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
	$dbh->quote($errorFile);
	$dbh->quote($errorMsg);
	$dbh->quote($referer);
	$dbh->quote($ip);
	$query = "insert into errorlog (page,referer,message,time,ip) values ($errorFile,$referer,$errorMsg,$time,$ip)";
	$count= $dbh->exec($query);
	$dbh=null;
    die();
}
catch (Exception $e){
	echo $e->getMessage();
	}
*/
?>